﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RsCms.Application;
using RsCms.Application.Tags.Dto;

namespace Plugin.RsCms.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TagsController : ControllerBase
    {
        ITagsAppService tagAppService;
        public TagsController(ITagsAppService tagAppService)
        {

            this.tagAppService = tagAppService;

        }
        /// <summary>
        /// 浏览标签
        /// </summary>
        /// <returns></returns>
        [HttpGet("list")]
        public async Task<object> GetList(int page,int pageSize)
        {
            return await tagAppService.PageAsync(page,pageSize);
        }

        [HttpGet("detail/{id}")]
        public async Task<object> GetDetailAsync(string id)
        {
            return await tagAppService.GetAsync(id);
        }


        [Authorize("admin")]
        [HttpPost("edit")]
        public async Task<object> SaveAsync([FromBody]TagsEditDto dto)
        {
            return await tagAppService.SaveAsync(dto);
            
        }
        [Authorize("admin")]
        [HttpPost("delete")]
        public async Task<object> DeleteAsync(string tagId)
        {
            await tagAppService.DeleteAsync(tagId);
            return "ok";
        }
    }
}
